/*
 * Copyright (C) 2009 Otávio Scherer Garcia
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.technorati4j.entity;

import com.googlecode.technorati4j.enums.ResponseFormat;

/**
 * Request entity for tag API.
 * 
 * @author Otávio Scherer Garcia
 * @version $Revision$
 */
public final class TagRequest
    implements Request {

    /** The Technorati API key. */
    private String key;

    /** Set this to the tag term you are searching posts for. */
    private String tag;

    /**
     * This allows you to request an output format, which by default is set to xml. At the moment only the XML (xml) and
     * RSS (rss) formats are supported. We plan to support the Atom Syndication Format as well as XOXO in the near
     * future.
     */
    private ResponseFormat format;

    /**
     * Set this to a number larger than 0 and smaller or equal to 100 and it will return limit number of posts for a
     * tag. By default this value is 20.
     */
    private int limit;

    /**
     * Set this to a number larger than 0 and you'll get the start+limit freshest posts, e.g. set it to limit+1, and
     * you'll get the second page of rankings.
     */
    private int start;

    /** Number of word characters to include in the post excerpts. By default 100 word characters are returned. */
    private int excerptSize;

    /** Number of word characters to include in the first post excerpt. By default 150 word characters are returned. */
    private int topExcerptSize;

    /**
     * The default constructor.
     */
    public TagRequest() {
    }

    /**
     * Constructor with mandatory attributes.
     * 
     * @param key The key attribute.
     * @param tag The tag attribute.
     */
    public TagRequest(String key, String tag) {
        setKey(key);
        setTag(tag);
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public ResponseFormat getFormat() {
        return format;
    }

    public void setFormat(ResponseFormat format) {
        this.format = format;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getExcerptSize() {
        return excerptSize;
    }

    public void setExcerptSize(int excerptSize) {
        this.excerptSize = excerptSize;
    }

    public int getTopExcerptSize() {
        return topExcerptSize;
    }

    public void setTopExcerptSize(int topExcerptSize) {
        this.topExcerptSize = topExcerptSize;
    }

    public String getParameters() {
        final StringBuilder str = new StringBuilder();
        str.append("key=");
        str.append(key);
        str.append("&tag=");
        str.append(tag);

        if (format != null) {
            str.append("&format=");
            str.append(format);
        }

        if (limit > 0 && limit <= 100) {
            str.append("&limit=");
            str.append(limit);
        }

        if (start > 0) {
            str.append("&start=");
            str.append(start);
        }

        if (excerptSize > 0) {
            str.append("&excerptSize=");
            str.append(excerptSize);
        }

        if (topExcerptSize > 0) {
            str.append("&topExcerptSize=");
            str.append(topExcerptSize);
        }

        return str.toString();
    }
}
